$(function () {
    var newDiv = $('.new-content1')
    var hotDiv = $('.hot-content1')


    var spans = $('.title')
    getData('useing/public')
    $.each(spans, function (index, el) {
        $(el).click(function () {
            $('.active').removeClass('active')
            $(this).addClass('active')
            var contentName = $(this).attr('content1')
            if (contentName === 'new-content') {
                newDiv.show()
                hotDiv.hide()
                getData('useing/public')

            } else if (contentName === 'hot-content') {
                newDiv.hide()
                hotDiv.show()
                getData('useing/master')
            } 
        })
    })

    function getData(url1) {
        $.ajax({
            url: 'http://localhost:3000/' + url1,
            type: 'get',
            success(data) {
                // console.log(data.length);
                // console.log(data[0][0].text);
                // debugger

                var str = '';
                var num = 0
                if (url1 === 'useing/public') {
                    console.log(data);
                    for (var i = 27; i >= 15; i--) {
                        str+='<div class=imgs><img src=../img/hot'
                        + i + '.jpg>' + '</img><p class=text>' +
                        data[num].text + '</p><p class=text1>' +
                         '<span>'+data[num].uName+
                         data[num].endTime+'</span></p><span class=jiaoBiao>'+
                         data[num].info_ty+'<span></div>'
                         num++
                     }
                    newDiv.html(str)
                } 
                else if (url1 === 'useing/master') {
                     for (var i = 0; i < data.length; i++) {
                        str+='<div class=imgs><img src=../img/hot'
                        + (i+1) + '.jpg>' + '</img><p class=text>' +
                        data[i].text + '</p><p class=text1>' +
                         '<span>'+data[i].uName+
                         data[i].endTime+'</span></p><span class=jiaoBiao>'+
                         data[i].info_ty+'</span></div>'
                     }
                    hotDiv.html(str)
                } 
            }
        })
    }








})